//
//  JBWUserInfoCacheManger.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/7/30.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWUserInfoCacheManger.h"

@interface JBWUserInfoCacheManger ()
@property(nonatomic,copy)NSString *  userInfoPlistPath ;

@end

@implementation JBWUserInfoCacheManger
+(instancetype )sharedInstance{
    
    static JBWUserInfoCacheManger *userInfoCacheManger = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userInfoCacheManger = [[JBWUserInfoCacheManger alloc]init];
    });
    return userInfoCacheManger;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        //获取本地沙盒路径
        NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        //获取完整路径
        NSString *documentsPath = [path objectAtIndex:0];
        self.userInfoPlistPath = [documentsPath stringByAppendingPathComponent:@"JBW_User_PropertyList.plist"];      
    }
    return self;
}


- (void)save:(NSMutableArray<NSMutableDictionary *>*)usersDicArray{
    //写入文件
    [usersDicArray writeToFile: self.userInfoPlistPath atomically:YES];
}

- (NSMutableArray *)readUserCache{
    
    return  [NSMutableArray arrayWithContentsOfFile:self.userInfoPlistPath];    
}
@end
